#ifndef PREDEFINED_SHAPE_HPP
#define PREDEFINED_SHAPE_HPP

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <math.h>
#include <vector>
#include <Constants.hpp>

namespace Geometry {

	//---------------------------------------------------------------------
	inline float DegreeToRadian(float degree) {
		return PI*degree/180.f;
	}
	//---------------------------------------------------------------------
	inline float Clamp(float val, float low, float high) {
		if (val < low) return low;
		else if (val > high) return high;
		else return val;
	}
	//---------------------------------------------------------------------
	inline int Clamp(int val, int low, int high) {
		if (val < low) return low;
		else if (val > high) return high;
		else return val;
	}
	//---------------------------------------------------------------------
	inline void SphericalThetaPhi(float* v, float& theta, float& phi) {		
		float p = atan2f(v[1], v[0]);
		phi = (p < 0.f) ? p + 2.f*PI : p;
		theta = acosf(Clamp(v[2], -1.f, 1.f));
	}	
	//---------------------------------------------------------------------
	inline void SphericalDirection(float sintheta, float costheta, float phi, float* vector) {
		vector[0] = sintheta * cosf(phi);
		vector[1] = sintheta * sinf(phi);
		vector[2] = costheta;
	}
	//---------------------------------------------------------------------
	inline int StrataIndex( int nTheta, int nPhi, int theta, int phi) {
		return phi*nTheta + theta;
	}
	//---------------------------------------------------------------------
	inline void ComputeNormal(float* normal, float* point0, float* point1, float* point2 ) {
		float u1[3], v1[3];
		Vector::Init3(u1, point1[0]-point0[0], point1[1]-point0[1], point1[2]-point0[2]);
		Vector::Init3(v1, point2[0]-point0[0], point2[1]-point0[1], point2[2]-point0[2]);	
		Vector::Cross3(normal, v1, u1 );
	}
	//---------------------------------------------------------------------
	void DrawLine(const float* start, const float* end, float size);
	//---------------------------------------------------------------------
	void DrawPoint(const float* position, float size);
	//---------------------------------------------------------------------
	void DrawReferential( float size );
	//---------------------------------------------------------------------
	void DrawGrid( int gridSize );
	//---------------------------------------------------------------------
	void DrawMaterial( const float* color ) ;
	//---------------------------------------------------------------------
	void DrawHemisphere( int nTheta, int nPhi, const std::vector<float>& weights ) ;
	//---------------------------------------------------------------------
	void Draw2DRectangle( int start[2], int end[2] );

} //namespace Geometry

#endif //PREDEFINED_SHAPE_HPP
